package com.airforce.mappers;

import com.airforce.model.topic;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface topicMapper {
    @Delete({
        "delete from topic",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into topic (id, name, ",
        "optimeA, optimeB, ",
        "optimeC, optimeD, ",
        "createtime, updatetime, ",
        "idx)",
        "values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
        "#{optimea,jdbcType=VARCHAR}, #{optimeb,jdbcType=VARCHAR}, ",
        "#{optimec,jdbcType=VARCHAR}, #{optimed,jdbcType=VARCHAR}, ",
        "#{createtime,jdbcType=TIMESTAMP}, #{updatetime,jdbcType=TIMESTAMP}, ",
        "#{idx,jdbcType=INTEGER})"
    })
    int insert(topic record);

    @InsertProvider(type=topicSqlProvider.class, method="insertSelective")
    int insertSelective(topic record);

    @Select({
        "select",
        "id, name, optimeA, optimeB, optimeC, optimeD, createtime, updatetime, idx",
        "from topic",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="optimeA", property="optimea", jdbcType=JdbcType.VARCHAR),
        @Result(column="optimeB", property="optimeb", jdbcType=JdbcType.VARCHAR),
        @Result(column="optimeC", property="optimec", jdbcType=JdbcType.VARCHAR),
        @Result(column="optimeD", property="optimed", jdbcType=JdbcType.VARCHAR),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="updatetime", property="updatetime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="idx", property="idx", jdbcType=JdbcType.INTEGER)
    })
    topic selectByPrimaryKey(Integer id);

    @Select({
            "select",
            "id, name, optimeA, optimeB, optimeC, optimeD, createtime, updatetime, idx",
            "from topic",
            "where idx = #{idx,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="optimeA", property="optimea", jdbcType=JdbcType.VARCHAR),
            @Result(column="optimeB", property="optimeb", jdbcType=JdbcType.VARCHAR),
            @Result(column="optimeC", property="optimec", jdbcType=JdbcType.VARCHAR),
            @Result(column="optimeD", property="optimed", jdbcType=JdbcType.VARCHAR),
            @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="updatetime", property="updatetime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="idx", property="idx", jdbcType=JdbcType.INTEGER)
    })
    topic selectByPrimaryIdx(Integer idx);

    @UpdateProvider(type=topicSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(topic record);

    @Update({
        "update topic",
        "set name = #{name,jdbcType=VARCHAR},",
          "optimeA = #{optimea,jdbcType=VARCHAR},",
          "optimeB = #{optimeb,jdbcType=VARCHAR},",
          "optimeC = #{optimec,jdbcType=VARCHAR},",
          "optimeD = #{optimed,jdbcType=VARCHAR},",
          "createtime = #{createtime,jdbcType=TIMESTAMP},",
          "updatetime = #{updatetime,jdbcType=TIMESTAMP},",
          "idx = #{idx,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(topic record);
    @Select("select * from topic where name like #{name}")
    List<topic> selectByname(String name );

    @Select("select * from topic  ORDER BY idx ")
    List<topic> selectByall();
}